package com.kkb.mybatis.config;

import org.dom4j.Element;

import java.util.List;

/**
 * User: zsl
 * Date: 2019/10/1018:29
 * Description:
 */
public class XMLMapperParser {

    private  Configuration configuration;

    public XMLMapperParser(Configuration configuration) {
        this.configuration = configuration;
    }

    /**
     * 解析 mapper.xml 文件
     * @param rootElement
     */
    public void parse(Element rootElement) {
        String namespace = rootElement.attributeValue("namespace");

        //mapper 标签下包含一些sql片段标签,resultmap标签等,resultmap 标签等,这些标签直接解析处理,而statement相关的标签
        List<Element> select = rootElement.elements("select");
        for (Element selectElement : select) {
            // select update delete insert 都对应一个 statement
            XMLStatementPaser xmlScriptPaser = new XMLStatementPaser(configuration);
            xmlScriptPaser.parseStatement(selectElement,namespace);
        }
    }

}
